<f:subview xmlns:f="http://java.sun.com/jsf/core"
  xmlns="http://www.w3.org/1999/xhtml"
  xmlns:c="http://java.sun.com/jstl/core"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:nxh="http://nuxeo.org/nxweb/html"
  xmlns:nxu="http://nuxeo.org/nxweb/util"
  xmlns:nxd="http://nuxeo.org/nxweb/document"
  xmlns:nxl="http://nuxeo.org/nxforms/layout"
  xmlns:nxw="http://nuxeo.org/nxforms/runtime/widget"
  id="#{widget.id}">

  <c:if test="#{nxl:isLikeViewMode(widget.mode)}">
    <nxu:set var="document" value="#{empty widgetProperty_document ? value : widgetProperty_document}">
    <nxu:set var="blobXPath"
             value="#{empty widgetProperty_blobXPath ? widget.fieldDefinitions[0].propertyName : widgetProperty_blobXPath}">
    <c:set var="blobHolder" value="#{blobHolderGenerator.getBlobHolder(document)}" />
    <c:set var="isMainBlob" value="#{blobXPath == blobHolder.xpath}" />
    <c:set var="blob" value="#{isMainBlob ? blobHolder.blob :  field_0}" />
    <c:set var="filename" value="#{empty field_1 ? blob.filename : field_1}" />
    <c:set var="blobLength" value="#{blob.length}" />
    <c:set var="fileUrl" value="#{nxd:fileUrl('downloadFile', document, isMainBlob ? 'blobholder:0' : blobXPath, filename)}" />

    <nxu:set var="actions"
             value="#{documentActions.getBlobActions(document, blobXPath, blob)}"
             cache="true">
    <nxh:graphicImage value="#{nxd:fileIconPath(blob)}"
                      rendered="#{! empty nxd:fileIconPath(blob)}" />
    <c:if test="#{blobLength >= 0}">
      <nxh:outputLink value="#{fileUrl}">
        <h:outputText value="#{filename}"/>
      </nxh:outputLink>
      <h:outputText styleClass="detail" value="#{nxu:printFileSize(blobLength)}"/>
    </c:if>
    <c:if test="#{blobLength lt 0}">
      <h:outputText value="#{filename}"/>
    </c:if>

    <div class="actionsColumn">
      <nxw:blobActions mode="view" actions="#{actions}" />
    </div>
    </nxu:set>
    </nxu:set>
    </nxu:set>
  </c:if>

  <c:if test="#{nxl:isBoundToEditMode(widget.mode)}">

    <nxu:inputFile id="#{widget.id}_file" value="#{field_0}"
      filename="#{field_1}" required="#{widgetProperty_required}" editFilename="false"
      onclick="#{widgetProperty_onclick}" onchange="#{widgetProperty_onchange}" />
    <h:message escape="false" styleClass="errorMessage" for="#{widget.id}_file"
      id="#{widget.id}_message" />

  </c:if>

</f:subview>
